<?php

class db {

	private $host;
	private $user;
	private $pass;
	private $charset;
	private $db;
	
	private $query;
	
	public function __construct(){
		
	}
	
	public function setHost( $host ){
		$this->host = $host;
	}
	
	public function setUser( $user ){
		$this->user = $user;
	}
	
	public function setPass( $pass ){
		$this->pass = $pass;
	}

	public function setCharset( $charset ){
		$this->charset = $charset;
	}
	
	public function setDb( $dbname ){
		$this->db = $dbname;
	}
	
	public function getHost(){
		return $this->host;
	}
	
	public function getUser(){
		return $this->user;
	}
	
	public function getPass(){
		return $this->pass;
	}
	
	public function getCharset(){
		return $this->charset;
	}
	
	public function getDb(){
		return $this->db;
	}
	
	public function Connect(){
		if( $this->getHost() && $this->getPass() && $this->getUser() ){
			$connect = mysql_connect( $this->getHost() , $this->getUser() , $this->getPass() );
		}
		if( $this->getCharset() ){
			mysql_query( "set names ".$this->getCharset() );
		}
		if( $this->getDb() ){
			mysql_select_db( $this->getDb() );
		}
	}
	
	
	
	public function query( $query ){
		return mysql_query($query);
	}
	
	public function fetch_row( $table , $id ){
		$query = ' SELECT * FROM  '.$table . ' WHERE 1 AND id= '.$id;
		return mysql_fetch_assoc( mysql_query($query) );
	}
	
	public function fetch_array( $table , $where = ''  ){
		$data = array();
		
		
		
		$query = ' SELECT * FROM  '.$table .' WHERE 1  '.$where.'  ORDER BY create_time DESC ';
		$res = $this->query( $query );
		while( $row = mysql_fetch_assoc($res) ){
			$data[] = $row;
		}
		return $data;
	}
}

?>